package br.com.edumobi.activities;

import android.content.Intent;
import android.os.Bundle;

import br.com.edumobi.R;
import br.com.edumobi.dados.modelos.Aluno;
import br.com.edumobi.excecoes.ExcecaoAutenticacaoMalsucedida;
import br.com.edumobi.fragments.LoginFragment;
import br.com.edumobi.P;

public class LoginActivity extends GenericaActivity implements LoginFragment.AcoesLoginFragment {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
    }

    @Override
    public Aluno onClickEntrar(String email, String senha) {
        try {
            return nuvem.autenticarAluno(email, senha);
        } catch (ExcecaoAutenticacaoMalsucedida excecao) {
            return null;
        }
    }

    @Override
    public void onClickCadastrese() {
        startActivity(new Intent(this, CadastroActivity.class));
    }

    @Override
    public void onClickEsqueciASenha() {
        startActivity(new Intent(this, EsqueciASenhaActivity.class));
    }

    @Override
    public void goDashboard(Aluno aluno) {
        Intent intentDashboard = new Intent(this, DashboardActivity.class);
        intentDashboard.putExtra(DashboardActivity.EXTRA_ALUNO, aluno);
        startActivity(intentDashboard);
    }

    @Override
    public String getPreferencesEmail() {
        return preferences.getString(P.PREFERENCES_USUARIO_EMAIL, P.STRING_NULL);
    }

    @Override
    public String getPreferencesSenha() {
        return preferences.getString(P.PREFERENCES_USUARIO_SENHA, P.STRING_NULL);
    }
}